import sys
from PyQt5.QtCore import Qt, QRectF
from PyQt5.QtGui import QPixmap, QTransform
from PyQt5.QtWidgets import QApplication, QMainWindow,QGraphicsScene,QGraphicsView, QGraphicsPixmapItem


def test(win: QMainWindow):
    # 图像显示主面板
    view = QGraphicsView(win)
    w = 500
    h = 316
    gemo = win.geometry()
    view.setGeometry((gemo.width()-w)/2, (gemo.height()-h)/2, w, h)
    # 场景
    scene = QGraphicsScene(win)  # 创建场景
    view.setScene(scene)
    rect = view.rect()
    scene.setSceneRect(10,10,rect.width()-20,rect.height()-20)
    scene.setBackgroundBrush(Qt.transparent)
    view.show()
    # 图元
    pixmap = QPixmap('./测试图像/500x316.jpg')
    item = QGraphicsPixmapItem(pixmap)  # 创建像素图元
    scene.addItem(item)

    #transform
    rect: QRectF = item.boundingRect()
    anchor = item.mapFromScene(rect.bottomRight())
    transform = QTransform()
    item.setTransformOriginPoint(anchor)
    item.setScale(0.5)
    #
    '''
    transform.translate(anchor.xRate(),anchor.yRate())
    transform.rotateRadians(3.14)
    item.setTransform(transform, True)
    transform = QTransform()
    transform.translate(-anchor.xRate(), -anchor.yRate())
    item.setTransform(transform, True)
    '''
    #
    p = item.transformOriginPoint()
    print(p.x(), ',', p.y())
    # item.setTransform(transform, True)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = QMainWindow()    # 加载主窗口
    win.resize(800, 600)
    win.show()
    test(win)
    sys.exit(app.exec_())
